<?php

define(C("ACCESSACTION"), true);

/**
 * 活动图片
 * @author Liqiang
 * @email 2074956@qq.com
 * @data  2016-2-6 19:11:46
 */
class PictureAction extends CommonAction {

    function _initialize() {
        $this->auth_allow_function[] = 'do_change_status';
        $this->auth_allow_function[] = 'upload';
        parent::_initialize();
    }

    function index() {
        $this->callback('');
    }

    function datatable() {
        $post = post_datatable();
        $voList = V('Picture')
//                ->where($post["sql_where"])
//                ->order($post["sql_order"])
                ->limit($post["sql_limit"])
                ->select();
        foreach ($voList as $key => $val) {
            $voList[$key]['tipimage'] = zooming(C('ACTIVE_IMAGES') . $voList[$key]['img']);
            $voList[$key]["master_img"] = '<img src="' . relative_path(C('ACTIVE_IMAGES') . $voList[$key]['img']) . '" style="width:100%">';
            $voList[$key]["img"] = '<img src="' . zooming(C('ACTIVE_IMAGES') . $voList[$key]['img']) . '" style="height:50px;width:50px">';
        }
        //   $this->func("$.Log", print_r(D()->getLastSql(), TRUE));
        $count = V('Picture')
//                ->where($post["sql_where"])
//                ->order($post["sql_order"])
                ->count();
        $this->callback(datatable($voList, $post["sEcho"], $count));
    }

    function do_change_status() {
        if ($this->isAjax()) {
            $row = D(TABLE_ACTIVE_ACTIVE_IMAGES)
                    ->where(array('id' => $this->_q('id')))
                    ->setField('status', array('exp', 'abs(`status` - 1)'));
            if ($row === false)
                $this->set_error();
            $jobinfo = D(TABLE_ACTIVE_ACTIVE_IMAGES)->find($this->_q('id'));
            $this->callback($jobinfo['status'] === '1');
        }
    }

}
